package com.jingyanzi.privilege.service.impl;


import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import com.jingyanzi.privilege.domain.BtnDO;
import com.jingyanzi.privilege.domain.DataAccessDO;
import com.jingyanzi.privilege.domain.EmployeeDO;
import com.jingyanzi.privilege.domain.FieldDO;
import com.jingyanzi.privilege.domain.JobsDO;
import com.jingyanzi.privilege.domain.OrgDO;
import com.jingyanzi.privilege.domain.MenuDO;
import com.jingyanzi.privilege.domain.RoleDO;
import com.jingyanzi.privilege.domain.RoleUserDO;
import com.jingyanzi.privilege.domain.TableDO;
import com.jingyanzi.privilege.domain.UserDO;
import com.jingyanzi.privilege.entity.SecurityBtn;
import com.jingyanzi.privilege.entity.SecurityDataaccess;
import com.jingyanzi.privilege.entity.SecurityEmployee;
import com.jingyanzi.privilege.entity.SecurityField;
import com.jingyanzi.privilege.entity.SecurityJobs;
import com.jingyanzi.privilege.entity.SecurityOrganization;
import com.jingyanzi.privilege.entity.SecurityMenu;
import com.jingyanzi.privilege.entity.SecurityRole;
import com.jingyanzi.privilege.entity.SecurityRoleuser;
import com.jingyanzi.privilege.entity.SecurityTable;
import com.jingyanzi.privilege.entity.SecurityUser;
import com.jingyanzi.privilege.util.BeanUtilsExtends;
import com.jingyanzi.privilege.util.Constants;

/**
 * @author reagan
 * @Description:基础服务类主要用来实现底层的通用方法
 */
public class BaseServiceImpl {
	
	/**
	 * 对象拷贝单个实体到对象中
	 * @param obj
	 * @return 返回DO对象
	 */
	public DataAccessDO getDataAccessDO(SecurityDataaccess obj) {
        if (obj == null) return null;
        DataAccessDO dst = new DataAccessDO();
        return BeanUtilsExtends.copyProperties(dst, obj) ? dst : null;
    }

	/**
	 * 对象拷贝多个实体到列表中
	 * @param List
	 * @return List
	 */
	public List<DataAccessDO> getDataAccessDOList(List<SecurityDataaccess> list) {
		List<DataAccessDO> result = new ArrayList<DataAccessDO>();
		if (list != null && !list.isEmpty()) {
			for (SecurityDataaccess org : list) {
				DataAccessDO org1 = getDataAccessDO(org);
				if (org1 != null) {
					result.add(org1);
				}
			}
		}
		return result;
	}
	
	
	/**
	 * 对象拷贝单个实体到对象中
	 * @param obj
	 * @return 返回DO对象
	 */
	public JobsDO getJobsDO(SecurityJobs obj) {
        if (obj == null) return null;
        JobsDO dst = new JobsDO();
        return BeanUtilsExtends.copyProperties(dst, obj) ? dst : null;
    }

	/**
	 * 对象拷贝多个实体到列表中
	 * @param List
	 * @return List
	 */
	public List<JobsDO> getJobsDOList(List<SecurityJobs> list) {
		List<JobsDO> result = new ArrayList<JobsDO>();
		if (list != null && !list.isEmpty()) {
			for (SecurityJobs org : list) {
				JobsDO org1 = getJobsDO(org);
				if (org1 != null) {
					result.add(org1);
				}
			}
		}
		return result;
	}
	
	/**
	 * 对象拷贝单个实体到对象中
	 * @param obj
	 * @return 返回DO对象
	 */
	public UserDO getUserDO(SecurityUser obj) {
        if (obj == null) return null;
        UserDO dst = new UserDO();
        return BeanUtilsExtends.copyProperties(dst, obj) ? dst : null;
    }

	/**
	 * 对象拷贝多个实体到列表中
	 * @param List
	 * @return List
	 */
	public List<UserDO> getUserDOList(List<SecurityUser> list) {
		List<UserDO> result = new ArrayList<UserDO>();
		if (list != null && !list.isEmpty()) {
			for (SecurityUser org : list) {
				UserDO org1 = getUserDO(org);
				if (org1 != null) {
					if(org.getLasttime() != null) {
						DateFormat dateForm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
						org1.setLasttimestr(dateForm.format(org.getLasttime()));
					}
					result.add(org1);
				}
			}
		}
		return result;
	}
	
	/**
	 * 对象拷贝单个实体到对象中
	 * @param obj
	 * @return 返回DO对象
	 */
	public EmployeeDO getEmployeeDO(SecurityEmployee obj) {
        if (obj == null) return null;
        EmployeeDO dst = new EmployeeDO();
        return BeanUtilsExtends.copyProperties(dst, obj) ? dst : null;
    }

	/**
	 * 对象拷贝多个实体到列表中
	 * @param List
	 * @return List
	 */
	public List<EmployeeDO> getEmployeeDOList(List<SecurityEmployee> list) {
		List<EmployeeDO> result = new ArrayList<EmployeeDO>();
		if (list != null && !list.isEmpty()) {
			for (SecurityEmployee org : list) {
				EmployeeDO org1 = getEmployeeDO(org);
				if (org1 != null) {
					result.add(org1);
				}
			}
		}
		return result;
	}
	
	public FieldDO getFieldDO(SecurityField obj) {
        if (obj == null) return null;
        FieldDO dst = new FieldDO();
        return BeanUtilsExtends.copyProperties(dst, obj) ? dst : null;
    }
	
	/**
	 * 对象拷贝多个实体到列表中
	 * @param List
	 * @return List
	 */
	public List<FieldDO> getFieldDOList(List<SecurityField> list) {
		List<FieldDO> result = new ArrayList<FieldDO>();
		if (list != null && !list.isEmpty()) {
			for (SecurityField org : list) {
				FieldDO org1 = getFieldDO(org);
				if (org1 != null) {
					result.add(org1);
				}
			}
		}
		return result;
	}
	
	public TableDO getTableDO(SecurityTable obj) {
        if (obj == null) return null;
        TableDO dst = new TableDO();
        return BeanUtilsExtends.copyProperties(dst, obj) ? dst : null;
    }
	
	public BtnDO getBtnDO(SecurityBtn obj) {
        if (obj == null) return null;
        BtnDO dst = new BtnDO();
        return BeanUtilsExtends.copyProperties(dst, obj) ? dst : null;
    }
	
	public List<BtnDO> getBtnDOList(List<SecurityBtn> list) {
		List<BtnDO> result = new ArrayList<BtnDO>();
		if (list != null && !list.isEmpty()) {
			for (SecurityBtn org : list) {
				BtnDO org1 = getBtnDO(org);
				if (org1 != null) {
					org1.setIsBtn(1);
					result.add(org1);
				}
			}
		}
		return result;
	}
	
	public MenuDO getMenuDO(SecurityMenu obj) {
        if (obj == null) return null;
        MenuDO dst = new MenuDO();
        return BeanUtilsExtends.copyProperties(dst, obj) ? dst : null;
    }
	
	public List<MenuDO> getMenuDOList(List<SecurityMenu> list) {
		List<MenuDO> result = new ArrayList<MenuDO>();
		if (list != null && !list.isEmpty()) {
			for (SecurityMenu org : list) {
				MenuDO org1 = getMenuDO(org);
				if (org1 != null) {
					org1.setIsMenu(1);
					result.add(org1);
				}
			}
		}
		return result;
	}
	
	public RoleDO getRoleDO(SecurityRole obj) {
        if (obj == null) return null;
        RoleDO dst = new RoleDO();
        return BeanUtilsExtends.copyProperties(dst, obj) ? dst : null;
    }
	public RoleUserDO getRoleUserDO(SecurityRoleuser obj) {
        if (obj == null) return null;
        RoleUserDO dst = new RoleUserDO();
        return BeanUtilsExtends.copyProperties(dst, obj) ? dst : null;
    }
	public List<RoleDO> getRoleDOList(List<SecurityRole> list) {
		List<RoleDO> result = new ArrayList<RoleDO>();
		if (list != null && !list.isEmpty()) {
			for (SecurityRole org : list) {
				RoleDO org1 = getRoleDO(org);
				if (org1 != null) {
					result.add(org1);
				}
			}
		}
		return result;
	}
	public List<RoleUserDO> getRoleUserList(List<SecurityRoleuser> list) {
		List<RoleUserDO> result = new ArrayList<RoleUserDO>();
		if (list != null && !list.isEmpty()) {
			for (SecurityRoleuser org : list) {
				RoleUserDO org1 = getRoleUserDO(org);
				if (org1 != null) {
					result.add(org1);
				}
			}
		}
		return result;
	}
	public OrgDO getOrgDO(SecurityOrganization obj) {
        if (obj == null) return null;
        OrgDO dst = new OrgDO();
        return BeanUtilsExtends.copyProperties(dst, obj) ? dst : null;
    }
	
	public List<OrgDO> getOrgDOList(List<SecurityOrganization> list) {
		List<OrgDO> result = new ArrayList<OrgDO>();
		if (list != null && !list.isEmpty()) {
			for (SecurityOrganization org : list) {
				OrgDO org1 = getOrgDO(org);

				if (org1 != null) {
					//设置中文值
					String typeName = Constants.orgTypeName.get(org.getType());
					org1.setTypeName(typeName);
					result.add(org1);
				}
			}
		}
		return result;
	}
	
	/**
	 * 判断整型数据是否无效： null或<1为无效,返回true; >=1为有效，返回false
	 */
	public static boolean isNumberInValid(Integer value) {
		if (value == null) {
			return true;
		} else if (value < 1) {
			return true;
		}
		return false;
	}
}
